﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars.Ribbon;
using MM.Common.Base;
using MM.Common.DBBase;
using MM.Commmon.UI;
using DevExpress.UserSkins;
using DevExpress.XtraEditors;
using DevExpress.Utils;
using DevExpress.LookAndFeel;
using DevExpress.Skins;
using DevExpress.Utils.Drawing;
using DevExpress.XtraBars;
using System.IO;
using System.Reflection;
using System.Diagnostics;
using DevExpress.XtraBars.Docking;
using MM.Common.Information;
using MM.Common.UI.Controls;

namespace MMTJ
{
    public partial class FrmRibbonMain : RibbonForm
    {
        #region 字段
        private string _MainPageModule = "";
        private string _MainPageObject = "";
        private FrmMessageClient _FrmClient;
        private FrmNoticeDisplay _FrmNotice;
        private DateTime _NoticeTime = DateTime.Now;
        #endregion

        public FrmRibbonMain()
        {
            InitializeComponent();
            this.Text = "MXHLY.NET --- [" + SystemInfo.SystemCode + "]";
        }

        public void Init()
        {
            Logger logger = new Logger("FrmRibbonMain:Init");
            long ticks = DateTime.Now.Ticks;
            base.Load += new EventHandler(FrmRibbonMain_Load);
            base.ResumeLayout(false);
            LoadUI.Guage("正在检查通知功能的使用权......", 0x37);
            _NoticeTime = DateTime.Now.AddYears(30);
            string commandtext = "SELECT SERIAL FROM MXHLY_SYS_MODULE WHERE MODULE_FILENAME = 'MM.Common.Information'";
            object obj2 = new object();
            SystemInfo.DbData.ExecuteScalar(commandtext, ref obj2);
            if ((obj2 != DBNull.Value) && (obj2 != null))
            {
                _NoticeTime = DateTime.Now;
            }
            LoadUI.Guage("检查通知功能的使用权完成", 0x41);
            if (GetSystem())
            {
                long num2 = DateTime.Now.Ticks;
                string str2 = ((num2 - ticks) / 0x2710).ToString();
                logger.Info("加载时间:" + str2);
                LoadUI.Guage("加载时间:" + str2, 0x4b);
                obj2 = new object();
                SystemInfo.DbData.ExecuteScalar("SELECT COUNT(*) FROM MXHLY_SYS_COMPUTER WHERE COMPUTER_CODE = :node", new DataParamCol(new DataParam[] { new InputDataParam("node", SystemInfo.ComputerID) }), ref obj2);
                if (Convert.ToInt16(obj2) == 0)
                {
                    SystemInfo.DbData.ExecuteSql("INSERT INTO MXHLY_SYS_COMPUTER (COMPUTER_CODE ,COMPUTER_NAME ,IP) VALUES (:node ,:name ,:ip)", new DataParamCol(new DataParam[] { new InputDataParam("node", SystemInfo.ComputerID), new InputDataParam("name", SystemInfo.ComputerName), new InputDataParam("ip", SystemInfo.ComputerIp) }));
                }
                LoadUI.Guage("正在加载主菜单......", 80);
                InitMenu();
                ribbon.EndInit();
                long num3 = DateTime.Now.Ticks;
                logger.Info(("登入加载时间:" + ((num3 - num2) / 0x2710)).ToString());
                LoadUI.Guage("加载主菜单完成", 90);
                if (SystemInfo.OrgSubName != string.Empty)
                {
                    bsiUser.Caption = SystemInfo.OrgHeadName + "(" + SystemInfo.OrgSubName + ")";
                }
                else
                {
                    bsiUser.Caption = SystemInfo.OrgHeadName;
                }
                bsiDataBase.Caption = SystemInfo.DbData.DataSource();
                CreateMessageClient();
                if (ConfigFunction.GetComputerConfig("SKIN", "N", "扩展的换肤功能") == "Y")
                {
                    OfficeSkins.Register();
                    BonusSkins.Register();
                }
                InitSkinGallery();
                SystemInfo.ReportDataServer.Register(SystemInfo.ComputerID);
            }
        }

        protected bool GetSystem()
        {
            bool flag = false;
            DataParamCol parm = new DataParamCol(new DataParam[] { new InputDataParam("code", SystemInfo.SystemCode) });
            string commandtext = "SELECT * FROM MXHLY_SYS_SYSTEM WHERE SYSTEM_CODE  = :code";
            DataTable dt = new DataTable();
            if (SystemInfo.DbData.Retrieve(commandtext, parm, ref dt) && (dt.Rows.Count == 1))
            {
                SystemInfo.SystemName = dt.Rows[0]["SYSTEM_NAME"].ToString();
                SystemInfo.CopyWrite = dt.Rows[0]["VERSION"].ToString();
                this._MainPageModule = ConfigFunction.GetEmpConfig("MAIN_PAGE_MODULE_FILENAME");
                this._MainPageObject = ConfigFunction.GetEmpConfig("MAIN_PAGE_OBJECT_NAME");
                if (string.IsNullOrEmpty(this._MainPageModule) || string.IsNullOrEmpty(this._MainPageObject))
                {
                    _MainPageModule = dt.Rows[0]["MAIN_PAGE_MODULE_FILENAME"].ToString().Trim();
                    _MainPageObject = dt.Rows[0]["MAIN_PAGE_OBJECT_NAME"].ToString().Trim();
                }
                flag = true;
            }
            else
            {
                LoadUI.CloseLoad();
                XtraMessageBox.Show("无此子系统, 请调整命令行参数!", "出错", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            if (DateTime.Now.AddMonths(3) > SystemInfo.LastDate)
            {
                Text = "MXHLY --- [" + SystemInfo.SystemCode + "]" + SystemInfo.SystemName + "[到期日期:" + SystemInfo.LastDate.ToString("yyyy年MM月dd日") + "]";
                return flag;
            }
            Text = "MXHLY --- [" + SystemInfo.SystemCode + "]" + SystemInfo.SystemName;
            return flag;
        }

        private void FrmRibbonMain_Load(object sender, EventArgs e)
        {
            if (SystemInfo.OperId <= 0)
            {
                base.Close();
            }
            else
            {
                //timer1 = new Timer();
                //timer1.Interval = 0x3e8;
                //timer1.Tick += new EventHandler(this.timer1_Tick);
                //timer1.Start();
            }
        }

        private void InitMenu()
        {
            string seqcode = Default_Function();
            bsiOper.Caption = SystemInfo.OperName;
            if (SystemInfo.OperInputCode == "1")
            {
                bbiInputCode.Caption = "首拼";
            }
            else
            {
                bbiInputCode.Caption = "五笔";
            }
            string str2 = ConfigFunction.GetEmpConfig("Min_Ribbon", "Y", "工具带最小化", "C");
            ribbon.Minimized = str2 == "Y";
            bciIsMin.Checked = str2 == "Y";
            string str3 = ConfigFunction.GetEmpConfig("Skin_Name", "Caramel", "皮肤名称", "C");
            defaultLookAndFeel1.LookAndFeel.SkinName = str3;
            string empConfig = ConfigFunction.GetEmpConfig("IME_Name");
            if (empConfig.Length == 0)
            {
                empConfig = InputLanguage.InstalledInputLanguages[0].LayoutName;
                ConfigFunction.CreateEmpConfig("IME_Name", empConfig, "C", "中文输入法名称", "");
            }
            IME.SetIme(empConfig);
            Create_Page(seqcode);
        }

        private void bbi_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            switch (e.Item.Tag.ToString())
            {
                case "ABOUT":
                    new FrmAbout { WindowState = FormWindowState.Normal }.ShowDialog();
                    return;

                case "IME":
                    new FrmSelectIME().ShowDialog();
                    return;

                case "CLAC":
                    new Process { StartInfo = { FileName = Environment.SystemDirectory + @"\calc.exe" } }.Start();
                    return;

                case "PASSWORD":
                    new FrmPassword().ShowDialog();
                    return;

                case "MINRIBBON"://最小化
                    {
                        this.ribbon.Minimized = this.bciIsMin.Checked;
                        string varvalue = this.bciIsMin.Checked ? "Y" : "N";
                        ConfigFunction.SetEmpConfig("Min_Ribbon", varvalue);
                        return;
                    }
                case "EXIT":
                    base.Close();
                    return;

                case "CLOSECHILD":
                    foreach (FrmBase base2 in base.MdiChildren)
                    {
                        if (!base2.CanClose)
                        {
                            XtraMessageBox.Show(base2.Text + "不能关闭?", "提示");
                            break;
                        }
                        base2.Close();
                    }
                    return;

                case "EMP_PARAMETER":
                    this.Execute("MM.Common.Support", "FrmParameterEmpSetup", "", false, "");
                    return;

                case "RELOGIN":
                    if (((this._FrmClient != null) || (base.MdiChildren.GetLength(0) <= 0)) && ((this._FrmClient == null) || (base.MdiChildren.GetLength(0) <= 1)))
                    {
                        if (this._FrmClient != null)
                        {
                            _FrmClient.Logout();
                            _FrmClient.Close();
                        }
                        this.timer1.Stop();
                        base.DialogResult = DialogResult.Retry;
                        base.Close();
                        return;
                    }
                    XtraMessageBox.Show("还有未关闭窗口，请关闭后再转换！", "提示");
                    break;

                default:
                    return;
            }
        }

        #region 自定义样式
        private void rgbiSkins_Gallery_ItemClick(object sender, GalleryItemClickEventArgs e)
        {
            if (this.rgbiSkins.Gallery.Groups[0].Items.Count == 0)
            {
                InitSkinGallery();
            }
            UserLookAndFeel.Default.SetSkinStyle(e.Item.Caption);
            ConfigFunction.SetEmpConfig("Skin_Name", e.Item.Caption);
        }

        private void rgbiSkins_Gallery_InitDropDownGallery(object sender, InplaceGalleryEventArgs e)
        {
            if (this.rgbiSkins.Gallery.Groups[0].Items.Count == 0)
            {
                InitSkinGallery();
            }
            e.PopupGallery.CreateFrom(this.rgbiSkins.Gallery);
            e.PopupGallery.AllowFilter = false;
            e.PopupGallery.ShowItemText = true;
            e.PopupGallery.AllowHoverImages = false;
            foreach (GalleryItemGroup group in e.PopupGallery.Groups)
            {
                foreach (GalleryItem item in group.Items)
                {
                    item.Image = item.HoverImage;
                }
            }
            e.PopupGallery.ColumnCount = 2;
            e.PopupGallery.ImageSize = new Size(70, 0x24);
        }

        private void InitSkinGallery()
        {
            SimpleButton button = new SimpleButton();
            foreach (SkinContainer container in SkinManager.Default.Skins)
            {
                button.LookAndFeel.SetSkinStyle(container.SkinName);
                GalleryItem item = new GalleryItem();
                int num = 0;
                if (container.SkinName.IndexOf("Office") > -1)
                {
                    num = 1;
                }
                this.rgbiSkins.Gallery.Groups[num].Items.Add(item);
                item.Image = GetSkinImage(button, 0x20, 0x11, 2);
                item.HoverImage = GetSkinImage(button, 70, 0x24, 5);
                item.Caption = container.SkinName;
                item.Hint = container.SkinName;
            }
            button.Dispose();
        }

        private Bitmap GetSkinImage(SimpleButton button, int width, int height, int indent)
        {
            Bitmap image = new Bitmap(width, height);
            using (Graphics graphics = Graphics.FromImage(image))
            {
                StyleObjectInfoArgs e = new StyleObjectInfoArgs(new GraphicsCache(graphics))
                {
                    Bounds = new Rectangle(0, 0, width, height)
                };
                button.LookAndFeel.Painter.GroupPanel.DrawObject(e);
                button.LookAndFeel.Painter.Border.DrawObject(e);
                e.Bounds = new Rectangle(indent, indent, width - (indent * 2), height - (indent * 2));
                button.LookAndFeel.Painter.Button.DrawObject(e);
            }
            return image;
        }
        #endregion

        private void CreateMessageClient()
        {
            if (ConfigFunction.GetSystemConfig("Message_Service", "N", "信息服务是否开通", "C") == "Y")
            {
                string server = ConfigFunction.GetSystemConfig("Message_IP", "127.0.0.1", "信息服务机器地址", "C");
                string s = ConfigFunction.GetSystemConfig("Message_Port", "1000", "信息服务机器端口号", "C");
                try
                {
                    int port = int.Parse(s);
                    _FrmClient = new FrmMessageClient(server, port);
                    _FrmClient.MdiParent = this;
                    _FrmClient.Init();
                }
                catch
                {
                    this._FrmClient.Dispose();
                }
            }
        }

        private string Default_Function()
        {
            DataParamCol parms = new DataParamCol(new DataParam[] { new InputDataParam("system_code", SystemInfo.SystemCode), new InputDataParam("emp_id", SystemInfo.OperId) });
            string data = "";
            SystemInfo.DbData.ExecuteScalar<string>("SELECT ORDER_NO FROM MXHLY_SYS_EMP_MENU WHERE SYSTEM_CODE = :system_code AND EMP_ID = :emp_id ", parms, ref data);
            return data;
        }

        private void bbiInputCode_ItemDoubleClick(object sender, ItemClickEventArgs e)
        {
            FrmInputCode code = new FrmInputCode();
            if (code.ShowDialog() == DialogResult.OK)
            {
                if (SystemInfo.OperInputCode == "1")
                {
                    this.bbiInputCode.Caption = "首拼";
                }
                else
                {
                    this.bbiInputCode.Caption = "五笔";
                }
            }
        }

        private void Create_Page(string seqcode)
        {
            DataTable menu = BaseDataHelper.GetMenu();
            FunctionInfo defaultfi = null;
            int index = 0;
            RibbonPage page = new RibbonPage();
            RibbonPageGroup group = new RibbonPageGroup();
            for (int i = 0; i < menu.Rows.Count; i++)
            {
                DataRow row = menu.Rows[i];
                string str = row["ORDER_NO"].ToString();
                string text = row["TITLE"].ToString();
                switch (str.Length)
                {
                    case 1:
                        {
                            page = new RibbonPage(text)
                            {
                                Name = "rbPage" + str
                            };
                            this.ribbon.Pages.Insert(index, page);
                            this.ribbon.Pages[index].Visible = false;
                            index++;
                            continue;
                        }
                    case 2:
                        {
                            if (CountFunctionItem(menu, i) > 0)
                            {
                                this.ribbon.Pages[index - 1].Visible = true;
                                group = new RibbonPageGroup
                                {
                                    Name = "rbPageGroup" + str,
                                    ShowCaptionButton = false
                                };
                                page.Groups.Add(group);
                                string funname = row["OBJECT_NAME"].ToString();
                                if (!(funname != ""))
                                {
                                    break;
                                }
                                string para = row["PARAMETER"].ToString();
                                string modname = row["MODULE_FILENAME"].ToString();
                                string serial = row["SERIAL"].ToString();
                                string str7 = row["OPEN_FLAG"].ToString();
                                FunctionInfo info2 = new FunctionInfo(funname, modname, para, serial, str7 == "Y");
                                BarButtonItem item = new BarButtonItem
                                {
                                    Caption = text,
                                    Id = this.ribbon.Items.Count,
                                    Name = "bbi" + str
                                };
                                if (!string.IsNullOrEmpty(row["PROMPT"].ToString()))
                                {
                                    SuperToolTip tip = new SuperToolTip();
                                    ToolTipItem item2 = new ToolTipItem
                                    {
                                        Text = row["PROMPT"].ToString()
                                    };
                                    tip.Items.Add(item2);
                                    item.SuperTip = tip;
                                }
                                string path = "";
                                if (!Convert.IsDBNull(row["ICO"]))
                                {
                                    path = row["ICO"].ToString();
                                }
                                if (path.Length > 0)
                                {
                                    path = Directory.GetCurrentDirectory() + @"\bmp\" + path;
                                    if (File.Exists(path))
                                    {
                                        Image image = Image.FromFile(path);
                                        item.RibbonStyle = RibbonItemStyles.Default;
                                        item.LargeGlyph = image;
                                    }
                                }
                                if (row["USED_FLAG"].ToString() == "N")
                                {
                                    item.Enabled = false;
                                }
                                item.Tag = info2;
                                if (seqcode == str)
                                {
                                    defaultfi = info2;
                                }
                                item.ItemClick += new ItemClickEventHandler(dynamic_bbi_ItemClick);
                                this.ribbon.Items.Add(item);
                                group.ItemLinks.Add(item);
                                group.Visible = true;
                            }
                            continue;
                        }
                    default:
                        {
                            continue;
                        }
                }
                BarSubItem item3 = CreateMenu(menu, ref i, seqcode, ref defaultfi);
                if ((item3.LinksPersistInfo.Count > 0) || (item3.Tag != null))
                {
                    this.ribbon.Items.Add(item3);
                    group.ItemLinks.Add(item3);
                    group.Visible = true;
                }
            }
            this.ribbon.SelectedPage = this.ribbon.Pages[0];
            if (defaultfi != null)
            {
                //体检菜单
                Execute(defaultfi.ModuleName, defaultfi.FunctionName, defaultfi.FunctionParameter, defaultfi.OpenFlag, defaultfi.ModuleSerial);
            }
        }

        private int CountFunctionItem(DataTable dt, int pi)
        {
            string str = dt.Rows[pi]["ORDER_NO"].ToString();
            int num = 0;
            for (int i = pi; i < dt.Rows.Count; i++)
            {
                string str2 = dt.Rows[i]["ORDER_NO"].ToString();
                if (str2.Length < str.Length)
                {
                    return num;
                }
                if ((str == str2.Substring(0, str.Length)) && (dt.Rows[i]["OBJECT_NAME"].ToString() != ""))
                {
                    num++;
                }
            }
            return num;
        }

        private void dynamic_bbi_ItemClick(object sender, ItemClickEventArgs e)
        {
            FunctionInfo tag = e.Item.Tag as FunctionInfo;
            if (tag != null)
            {
                Execute(tag.ModuleName, tag.FunctionName, tag.FunctionParameter, tag.OpenFlag, tag.ModuleSerial);
            }
        }

        private BarSubItem CreateMenu(DataTable dt, ref int pi, string seqcode, ref FunctionInfo defaultfi)
        {
            DataRow row = dt.Rows[pi];
            string str = row["ORDER_NO"].ToString();
            string str2 = row["TITLE"].ToString();
            BarSubItem item = new BarSubItem
            {
                Caption = str2,
                Name = "bsi" + str
            };
            string path = "";
            if (!Convert.IsDBNull(row["ICO"]))
            {
                path = row["ICO"].ToString();
            }
            if (path.Length > 0)
            {
                path = Directory.GetCurrentDirectory() + @"\bmp\" + path;
                if (File.Exists(path))
                {
                    Image image = Image.FromFile(path);
                    item.LargeGlyph = image;
                }
            }
            pi++;
            while (pi < dt.Rows.Count)
            {
                row = dt.Rows[pi];
                string str4 = row["ORDER_NO"].ToString();
                string str5 = row["TITLE"].ToString();
                if ((str4.Length == (str.Length + 1)) && (str4.Substring(0, str.Length) == str))
                {
                    string funname = row["OBJECT_NAME"].ToString();
                    string para = row["PARAMETER"].ToString();
                    string modname = row["MODULE_FILENAME"].ToString();
                    string serial = row["SERIAL"].ToString();
                    string str10 = row["OPEN_FLAG"].ToString();
                    if (funname == "")
                    {
                        BarSubItem item2 = this.CreateMenu(dt, ref pi, seqcode, ref defaultfi);
                        if (item2.LinksPersistInfo.Count > 0)
                        {
                            this.ribbon.Items.Add(item2);
                            item.LinksPersistInfo.Add(new LinkPersistInfo(item2));
                        }
                    }
                    else
                    {
                        FunctionInfo info = new FunctionInfo(funname, modname, para, serial, str10 == "Y");
                        BarButtonItem item3 = new BarButtonItem
                        {
                            Caption = str5,
                            Id = this.ribbon.Items.Count,
                            Name = "bbi" + str4
                        };
                        if (!string.IsNullOrEmpty(row["PROMPT"].ToString()))
                        {
                            SuperToolTip tip = new SuperToolTip();
                            ToolTipItem item4 = new ToolTipItem
                            {
                                Text = row["PROMPT"].ToString()
                            };
                            tip.Items.Add(item4);
                            item3.SuperTip = tip;
                        }
                        path = "";
                        if (!Convert.IsDBNull(row["ICO"]))
                        {
                            path = row["ICO"].ToString();
                        }
                        if (path.Length > 0)
                        {
                            path = Directory.GetCurrentDirectory() + @"\bmp\" + path;
                            if (File.Exists(path))
                            {
                                Image image2 = Image.FromFile(path);
                                item3.RibbonStyle = RibbonItemStyles.Default;
                                item3.Glyph = image2;
                            }
                        }
                        if (row["USED_FLAG"].ToString() == "N")
                        {
                            item3.Enabled = false;
                        }
                        item3.Tag = info;
                        if (seqcode == str4)
                        {
                            defaultfi = info;
                        }
                        item3.ItemClick += new ItemClickEventHandler(this.dynamic_bbi_ItemClick);
                        this.ribbon.Items.Add(item3);
                        item.LinksPersistInfo.Add(new LinkPersistInfo(item3));
                    }
                }
                else
                {
                    pi--;
                    return item;
                }
                pi++;
            }
            return item;
        }

        private bool Execute(string mod, string fun, string para)
        {
            string assemblyFile = SystemInfo.RunPath + mod + ".dll";
            try
            {
                FrmFunctionBase base2 = (FrmFunctionBase)Assembly.LoadFrom(assemblyFile).CreateInstance(mod + "." + fun);
                base2.MdiParent = this;
                if (base2.Init())
                {
                    base2.CallMessage(false, para);
                    base2.Show();
                    return true;
                }
                base2.Close();
            }
            catch (Exception exception)
            {
                LoadUI.CloseLoad();
                Log.WriteError("FrmMain", "Run", exception.Message + " " + exception.InnerException);
                XtraMessageBox.Show(exception.Message);
            }
            return false;
        }

        private bool Execute(string mod, string fun, string para, bool openflag, string serial)
        {
            bool flag = false;
            bool flag2 = false;
            if (!openflag)
            {
                foreach (Form form in base.MdiChildren)
                {
                    if ((form.Name == fun) && (form.ProductName == mod))
                    {
                        form.Focus();
                        flag2 = true;
                        break;
                    }
                }
            }
            if (!flag2)
            {
                string assemblyFile = SystemInfo.RunPath + mod + ".dll";
                try
                {
                    FrmFunctionBase base2 = (FrmFunctionBase)Assembly.LoadFrom(assemblyFile).CreateInstance(mod + "." + fun);
                    base2.FunctionParameter = para;
                    base2.MdiParent = this;
                    if (base2.Init())
                    {
                        base2.Visible = true;
                        base2.Show();
                        flag = true;
                    }
                    else
                    {
                        base2.Close();
                        XtraMessageBox.Show("调用运行库不成功!\n" + SystemInfo.DbData.ErrorMessage, "出错");
                    }
                    LoadUI.CloseLoad();
                }
                catch (Exception exception)
                {
                    LoadUI.CloseLoad();
                    XtraMessageBox.Show(string.Concat(new object[] { "调用运行库不成功!\n", exception.Message, "\r\n", exception.InnerException }), "出错");
                }
            }
            return flag;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.timer1.Stop();
            this.bsiTime.Caption = DateTime.Now.ToString("  yy-MM-dd HH:mm:ss  ");
            if (SystemInfo.MessageDataServer.MessageStatus != EMessageStatus.None)
            {
                this.bbiMessage.Visibility = BarItemVisibility.Always;
            }
            else
            {
                this.bbiMessage.Visibility = BarItemVisibility.Never;
            }
            if ((this._FrmClient != null) && !this._FrmClient.Visible)
            {
                switch (SystemInfo.MessageDataServer.MessageStatus)
                {
                    case EMessageStatus.Disconnect:
                        bbiMessage.Caption = "断开";
                        break;

                    case EMessageStatus.Wait:
                        bbiMessage.Caption = "";
                        break;

                    case EMessageStatus.Call:
                        PopupMessage();
                        break;

                    case EMessageStatus.New:
                        bbiMessage.Caption = "新消息";
                        break;
                }
            }
            ExecuteMessage();
            this.timer1.Start();
            if (DateTime.Now >= this._NoticeTime.AddMinutes(10.0))
            {
                this._NoticeTime = DateTime.Now;
                string commandtext = "SELECT INFO.NOTICE_NO, INFO.NOTICE_TITLE, INFO.NOTICE_CONTENT ,INFO.END_TIME \r\n   FROM MXHLY_SYS_NOTICE_INFO INFO ,MXHLY_SYS_NOTICE_DETAIL DTL \r\n   WHERE DTL.NOTICE_NO = INFO.NOTICE_NO AND DTL.EMP_ID = :EMP_ID AND INFO.END_TIME > SYSDATE AND DTL.STATUS = 'N'";
                DataParamCol parm = new DataParamCol();
                parm.Add("emp_id", SystemInfo.OperId);
                DataTable dt = new DataTable();
                SystemInfo.DbData.Retrieve(commandtext, parm, ref dt);
                if (dt.Rows.Count > 0)
                {
                    if ((this._FrmNotice == null) || !this._FrmNotice.Visible)
                    {
                        this._FrmNotice = new FrmNoticeDisplay();
                        this._FrmNotice.MdiParent = this;
                        this._FrmNotice.FunctionParameter = "Popup";
                        this._FrmNotice.Show();
                    }
                    else
                    {
                        this._FrmNotice.RefreshNotice();
                        this._FrmNotice.Focus();
                    }
                }
            }
        }

        private void bbiMessage_ItemDoubleClick(object sender, ItemClickEventArgs e)
        {
            PopupMessage();
        }

        private void PopupMessage()
        {
            if ((((this._FrmClient != null) && (SystemInfo.MessageDataServer.MessageStatus != EMessageStatus.None)) && ((SystemInfo.MessageDataServer.MessageStatus != EMessageStatus.Disconnect) || this._FrmClient.Init())) && (SystemInfo.MessageDataServer.MessageStatus != EMessageStatus.Disconnect))
            {
                this._FrmClient.MdiParent = this;
                this._FrmClient.Show();
                this.bbiMessage.Caption = "....";
            }
        }

        private void ExecuteMessage()
        {
            lock (SystemInfo.MessageDataServer.ReceiveFunctionInformation)
            {
                for (int i = 0; i < SystemInfo.MessageDataServer.ReceiveFunctionInformation.Count; i++)
                {
                    try
                    {
                        FunctionInfo info2;
                        FunctionInfo info3;
                        int num2;
                        ReceiveFunctionInformation information = SystemInfo.MessageDataServer.ReceiveFunctionInformation.Dequeue();
                        string code = information.Code;
                        if (code == null)
                        {
                            goto Label_02A6;
                        }
                        if ((!(code == "New TabWindow") && !(code == "Active TabWindow")) && !(code == "Open TabWindow"))
                        {
                            if (code == "Display Title")
                            {
                                goto Label_0160;
                            }
                            if (code == "Close Title")
                            {
                                goto Label_0255;
                            }
                            goto Label_02A6;
                        }
                        FunctionInfo body = (FunctionInfo)information.Body;
                        bool flag = true;
                        if ((information.Code == "Active TabWindow") || (information.Code == "Open TabWindow"))
                        {
                            foreach (Form form in base.MdiChildren)
                            {
                                if ((form.ProductName == body.ModuleName) && (form.Name == body.FunctionName))
                                {
                                    form.Activate();
                                    //((FrmBase)form).CallMessage(false, body.FunctionParameter);
                                    flag = false;
                                    break;
                                }
                            }
                        }
                        if (flag && (information.Code != "Active TabWindow"))
                        {
                            this.Execute(body.ModuleName, body.FunctionName, body.FunctionParameter);
                        }
                        continue;
                    Label_0160:
                        info2 = (FunctionInfo)information.Body;
                        if ((info2.ModuleName + "." + info2.FunctionName) != this.UCTitleControl.GetType().FullName)
                        {
                            Assembly assembly = Assembly.LoadFrom(SystemInfo.RunPath + info2.ModuleName + ".dll");
                            UCTitleControl = (UCTitleControlBase)assembly.CreateInstance(info2.ModuleName + "." + info2.FunctionName);
                            dockPanelTitle.Visibility = DockVisibility.Visible;
                            dockPanelTitle.Height = UCTitleControl.Height + 1;
                            dockPanel2_Container.Controls.Add(this.UCTitleControl);
                            UCTitleControl.Dock = DockStyle.Top;
                        }
                        dockPanelTitle.Visibility = DockVisibility.Visible;
                        UCTitleControl.Init(info2.FunctionParameter);
                        continue;
                    Label_0255:
                        info3 = (FunctionInfo)information.Body;
                        if ((info3.ModuleName + "." + info3.FunctionName) == UCTitleControl.GetType().FullName)
                        {
                            dockPanelTitle.Visibility = DockVisibility.Hidden;
                        }
                        continue;
                    Label_02A6:
                    Label_031F:
                        foreach (Form form2 in Application.OpenForms)
                        {
                            if (form2 is FrmBase)
                            {
                                for (num2 = 0; i < ((FrmBase)form2).InformationCode.Length; num2++)
                                {
                                    if (((FrmBase)form2).InformationCode[num2] == information.Code)
                                    {
                                        ((FrmBase)form2).CallMessage(false, information.Body.ToString());
                                        goto Label_031F;
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
        }

        private void FrmRibbonMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (SystemInfo.OperId > 0)
            {
                if (SystemInfo.DbData.IsOpen)
                {
                    foreach (FrmBase base2 in base.MdiChildren)
                    {
                        if (!base2.CanClose)
                        {
                            XtraMessageBox.Show(base2.Text + " 不能关闭，退出系统不成功?", "提示");
                            e.Cancel = true;
                            return;
                        }
                    }
                    if (base.DialogResult == DialogResult.Retry)
                    {
                        return;
                    }
                    if (XtraMessageBox.Show("是否真的退出系统?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        e.Cancel = true;
                        return;
                    }
                    Log.WriteLogSysInfo("退出" + SystemInfo.SystemName);
                    base.DialogResult = DialogResult.Yes;
                    foreach (Form form in base.MdiChildren)
                    {
                        form.Close();
                    }
                    if (this._FrmClient != null)
                    {
                        this._FrmClient.Logout();
                    }
                }
                SystemInfo.DbData.DBClose();
            }
        }
    }
}
